package com.ucsd.cse135.support;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import com.ucsd.cse135.db.Database;

public class Location {

	private int id;
	private String name;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	/** Method to get all "real" countries **/
	
	public ArrayList<Location> getCountries() {
		
		try {
			
			Connection conn = Database.open();
		
			String sql = "SELECT id, name FROM location WHERE state = 0;";
		
			PreparedStatement preStmt = conn.prepareStatement(sql);
			ResultSet rs = preStmt.executeQuery();
			
			ArrayList<Location> cAl = new ArrayList<Location>();
			
			while(rs.next())
			{
				Location c = new Location();
				
				c.setId(rs.getInt("id"));
				c.setName(rs.getString("name"));
				
				cAl.add(c);
			}
			
			rs.close();
			preStmt.close();
			Database.close();
			
			return cAl;
			
		}
		catch(Exception e) {
			
			Database.close();
			
			return null;
			
		}
	}

}
